import express from 'express';
import { upload, handleUploadError } from '../common/upload.js';
import Result from '../common/result.js';

const router = express.Router();

// Generic file upload endpoint
router.post('/upload', 
  upload.single('file'),
  handleUploadError,
  (req, res) => {
    if (!req.file) {
      return Result.error(res, 'No file uploaded');
    }
    // Return relative path for file access
    const fileUrl = `/uploads/${req.file.filename}`;
    return Result.success(res, { url: fileUrl });
  }
);

export default router; 